		$(function(){
				/* 分页 */
				var pager = $('#dg').datagrid().datagrid('getPager');	
		})
		// 重新载入当前页面数据
		function refresh(){
			$('#dg').datagrid('reload');    
		}
		//启用/删除formatter
		function isdelformatter(value,row,index){
			if(value=="1"){
				return '<span><a href="#" style="text-decoration:none;color:green"'
					+'onclick=qidel("'+row.sysId+'",'+value+'); >已 启 用</a></span>';
			}else if(value=="2"){
				return '<span><a href="#" style="text-decoration:none;color:red" '
					+'onclick=qidel("'+row.sysId+'",'+value+'); >已 禁 用</a></span>';
			}else{
				return value;
			}
		}
		//启用/删除
		function qidel(sysId,value){
			var isDel = "";
			var delName="";
			if(value=='1'){
				isDel='2';
				delName="禁用";
			}
			if(value=='2'){
				isDel='1';
				delName="启用";
			}
			  
			$.messager.confirm('确认','您确认想要 [ '+delName+' ] 数据吗？',function(r){    
			    if (r){    
			    	$.ajax({  
						url:'../network/updateNetwork',
						type:'post',
						data:{
						"sysId":sysId,
						"isDel":isDel
						},
						dataType:'json',
						error:function(){
							$.messager.alert("提示",delName+"异常","error");
						}, 
						success:function(map){ 
							var row = map.row;
							if(row>=0){
								$.messager.alert("提示",delName+"成功","info");
								$('#dg').datagrid("reload");
								return;
							}else{
								$.messager.alert("提示",delName+"失败","error");
								return;
							}
						}  
					});    
			    }    
			});
		}
		/* 点击搜索时触发 */
		function init(){
			
			var networkName = $("#networkNameMsgId").val().replace(/\s/g, "");//网点名称
			
			var phone=$("#phoneMsgId").val().replace(/\s/g, "");//电话 
			var isDel = $("#isDelMsgId").combobox('getValue');//1显示，2禁用
			
			$('#dg').datagrid({
				url:'../network/queryNetwork?dt='+new Date().getTime(),
				queryParams: {
					networkName: networkName,
					phone:phone,
					isDel:isDel
				}

			}); 
		}
		/* 点击重置时触发 */
		function chongzhi(){
			$('#networkNameMsgId').textbox('clear');
			$('#phoneMsgId').textbox('clear');
			$('#isDelMsgId').combobox('setValue', '');


		}
		/* 点击 新增用户时触发 */
		function addOrUpdateNetwork(type){	
			var dialogTitle="";
			var typeMsg = "";
			var urlType = "";
			var textType="";
			var sysIdVal="";
			$("#imgId").val("");
			if(type=='1'){
				//先对表单进行清空
				$('#addForm').form('reset');		
				$('#networkNameId').textbox('setValue','');
				$('#addressId').textbox('setValue','');
				$('#phoneId').textbox('setValue','');
				$('#mapImg').val("");
				$("#show_img").attr("src","../../images/sys/noimage.jpg");
				
				dialogTitle="新增网点信息";
				typeMsg="新增网点";
				textType="保存";
				urlType='../network/addNetwork';
			}else if(type=='2'){
				var row = $('#dg').datagrid('getSelected');
				if (row==null){
					$.messager.alert("友情提示","[请选择要修改的网点!]","error");
					return;
				}
				$('#networkNameId').textbox('setValue',row.networkName);
				$('#addressId').textbox('setValue',row.address);
				$('#phoneId').textbox('setValue',row.phone);
				$('#mapImg').val(row.img);
				$("#show_img").attr("src","../../images/uploadimg/"+row.img);
				sysIdVal=row.sysId;
				
				dialogTitle="修改网点信息";
				typeMsg="修改网点";
				textType="修改";
				urlType='../network/updateNetwork';
			}else{
				return;
			}
			$('#add').show();
				$('#add').dialog({
					title: dialogTitle,
					width: 400,
					height: 350,
					closed: false,
					cache: false,
					modal: true,
					buttons:[{
						text:textType,
						iconCls:'icon-ok',
						handler:function(){
						  	if($("#addForm").form('validate')){
						  		var networkName = $("#networkNameId").val().replace(/\s/g, "")
						  		if(networkName==""){
						  			$.messager.alert("友情提示","网点名称不允许为空","error");
						  			return;
						  		}
						  		var address = $("#addressId").val().replace(/\s/g, "");
						  		if(address==""){
						  			$.messager.alert("友情提示","地址不允许为空","error");
						  			return;
						  		}
						  		
						  		var phone = $("#phoneId").val().replace(/\s/g, "")
						  		if(phone==""){
						  			$.messager.alert("友情提示","联系电话不允许为空","error");
						  			return;
						  		}
						  		
						  		var img = $("#mapImg").val().replace(/\s/g, "");/* 图片 */
						  
						  		if(img==""){
						  			$.messager.alert("友情提示","请上传地图图片","error");
						  			return;
						  		}
							  	$.ajax({  
									url:urlType,
									type:'post',
									data:{
										'networkName':networkName,
										'address':address,
										'phone':phone,
										'img':img,
										'sysId':sysIdVal
									},
									dataType:'json',
									error:function(){
										$.messager.alert("友情提示",typeMsg+"异常","error");
									}, 
									success:function(data){
										var row = data.row;
										if(row==1){
											$.messager.alert("友情提示",typeMsg+"成功!","info");
											$('#dg').datagrid("reload");
											$('#add').window('close');  // close a window  
										}else{
											$.messager.alert("友情提示",typeMsg+"失败!","info");
										}
										
										
									}  
								});
						  	}
						    
						}
							
					},{
						text:'退出',
						iconCls:'icon-no',
						handler:function(){
							$('#add').dialog('close');
						}
					}]
				});
			}
		//创建时间formatter
		function createTimeformatter(value,row,index){
			if(value==null || value==""){
				return "";
			}
			var now = new Date(value);
			var time= now.format("yyyy-MM-dd hh:mm:ss");
			return time;
		}
		
		//图片上传
		 function fn_img_upload(){
			  var url = '../upload/fileUpload';
			  var suffixStr = "jpg,JPG,png,PNG,gif,GIF,bmp,BMP";
			  var savePath = ",images,uploadimg";/* 图片存储路径 */
			  $.ajaxFileUpload({//String fileObjectId,int MaxSize,String suffixStr,String savePath,int width,int height
		           url: url+'?fileObjectId=imgId&MaxSize='+0+'&suffixStr='+suffixStr+'&savePath='+savePath+'&width='+0+'&height='+0, //用于文件上传的服务器端请求地址
		           secureuri: false, //是否需要安全协议，一般设置为false
		           fileElementId: 'imgId', //文件上传域的ID
		           dataType: 'json', //返回值类型 一般设置为json
		           success: function (data, status)  //服务器成功响应处理函数
		           {
		               if(data.success=="true"){
		            	   $("#show_img").attr("src","../../images/uploadimg/"+data.imgurl);
		               	   $("#mapImg").val(data.imgurl);
		               }else{
		            	   $.messager.alert("提示",data.msg,"error");
		             		return;
		               }
		           },
		           error: function (data, status, e)//服务器响应失败处理函数
		           {
		        	   $("#imgId").val("");
		        	   $("#mapImg").val("");
		        	   $.messager.alert("提示",e,"error");
						return;
		           }
		    })
		} 
		Date.prototype.format = function(format){
			var o = {
			"M+" : this.getMonth()+1, //month
			"d+" : this.getDate(), //day
			"h+" : this.getHours(), //hour
			"m+" : this.getMinutes(), //minute
			"s+" : this.getSeconds(), //second
			"q+" : Math.floor((this.getMonth()+3)/3), //quarter
			"S" : this.getMilliseconds() //millisecond
			}

			if(/(y+)/.test(format)) {
			format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
			}

			for(var k in o) {
			if(new RegExp("("+ k +")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
			}
			}
			return format;
		}